<template>
    <!-- 对话框表单 -->
    <el-dialog class="ba-operate-dialog" :close-on-click-modal="false" :destroy-on-close="true"
        :model-value="['Add', 'Edit'].includes(baTable.form.operate!)" @close="baTable.toggleForm">
        <template #header>
            <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
                {{ baTable.form.operate ? t(baTable.form.operate) : '' }}
            </div>
        </template>

        <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
            <div class="ba-operate-form" :class="'ba-' + baTable.form.operate + '-form'"
                :style="config.layout.shrink ? '' : 'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'">
                <el-form ref="formRef" @keyup.enter="baTable.onSubmit(formRef)" :model="baTable.form.items"
                    :label-position="config.layout.shrink ? 'top' : 'right'"
                    :label-width="baTable.form.labelWidth + 'px'" :rules="rules" v-if="!baTable.form.loading">

                    <el-form-item prop="live_name" label="直播间名称">
                        <el-input v-model="baTable.form.items!.live_name" type="string"
                            placeholder="请输入直播间名称"></el-input>
                    </el-form-item>
                    <el-form-item prop="author_name" label="直播人">
                        <el-input v-model="baTable.form.items!.author_name" type="string"
                            placeholder="请输入直播人"></el-input>
                    </el-form-item>
                    <FormItem label="封面图" type="image" v-model="baTable.form.items!.live_image" />
                    <el-form-item prop="play_url" label="播放地址">
                        <el-input v-model="baTable.form.items!.play_url" type="string" placeholder="请输入播放地址"></el-input>
                    </el-form-item>
                    <el-form-item prop="ingest_url" label="推流地址">
                        <el-input v-model="baTable.form.items!.ingest_url" type="string" placeholder="请输入播放地址"></el-input>
                    </el-form-item>
                    <el-form-item prop="pull_stream_url" label="拉流地址">
                        <el-input v-model="baTable.form.items!.pull_stream_url" type="string" placeholder="请输入播放地址"></el-input>
                    </el-form-item>
                    <FormItem label="是否收费" v-model="baTable.form.items!.is_charges" type="radio"
                        :data="{ content: { '0': '免费', '1': '收费' }, childrenAttr: { border: true } }" />
                    <el-form-item prop="money" label="收费金额">
                        <el-input v-model="baTable.form.items!.money" type="string" placeholder="请输入收费金额"></el-input>
                    </el-form-item>
                    <FormItem label="赛事类型" v-model="baTable.form.items!.type" type="radio"
                        :data="{ content: { 'football': '足球', 'basketball': '篮球' }, childrenAttr: { border: true } }" />
                    <el-form-item prop="relevance_matches" label="关联赛事">
                        <el-input v-model="baTable.form.items!.relevance_matches" type="string"
                            placeholder="请输入关联赛事"></el-input>
                    </el-form-item>
                    <!-- <el-form-item prop="synopsis" label="简介">
                        <el-input v-model="baTable.form.items!.synopsis" type="textarea" placeholder="请输入简介"></el-input>
                    </el-form-item> -->
                    <el-form-item label="权重">
                        <el-input v-model="baTable.form.items!.weigh" type="number" placeholder="请输入权重"></el-input>
                    </el-form-item>
                    <!-- <FormItem label="内容" type="editor" v-model="baTable.form.items!.content" /> -->

                    <!-- <FormItem
                        label="显示"
                        v-model="baTable.form.items!.status"
                        type="radio"
                        :data="{ content: { '0': '隐藏', '1': '显示' }, childrenAttr: { border: true } }"
                    /> -->
                </el-form>
            </div>
        </el-scrollbar>
        <template #footer>
            <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
                <el-button @click="baTable.toggleForm('')">{{ t('Cancel') }}</el-button>
                <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)"
                    type="primary">
                    {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') :
        t('Save') }}
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref, inject } from 'vue'
import { useI18n } from 'vue-i18n'
import type baTableClass from '/@/utils/baTable'
import FormItem from '/@/components/formItem/index.vue'
import { buildValidatorData } from '/@/utils/validate'
import type { FormInstance, FormItemRule } from 'element-plus'
import { useConfig } from '/@/stores/config'

const config = useConfig()
const formRef = ref<FormInstance>()
const baTable = inject('baTable') as baTableClass

const { t } = useI18n()

const rules: Partial<Record<string, FormItemRule[]>> = reactive({
    title: [buildValidatorData({ name: 'required', title: '名称' })],
    icon: [buildValidatorData({ name: 'required', title: '图标' })],
})
</script>

<style scoped lang="scss"></style>
